<template>
<view class="content">
	<view class="box" :style='{"minHeight":"100%","padding":"200rpx 60rpx 0 60rpx","alignItems":"flex-start","background":"url(http://codegen.caihongy.cn/20250208/663f8e6fd10444f08c8ffd7a9da52baf.png) no-repeat center top / 100% auto","display":"flex","width":"100%","height":"auto"}'>
		<view :style='{"width":"100%","padding":"0","position":"relative","background":"none","height":"auto"}'>
			<image :style='{"width":"160rpx","margin":"0 auto 24rpx auto","borderRadius":"8rpx","display":"none","height":"160rpx"}' src="http://codegen.caihongy.cn/20201114/7856ba26477849ea828f481fa2773a95.jpg" mode="aspectFill"></image>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='laoren'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">账号：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.zhanghao"  type="text"  class="uni-input" name="" placeholder="请输入手机号" />
			</view>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='laoren'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">密码：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.mima" type="password"  class="uni-input" name="" placeholder="请输入密码" />
			</view>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='laoren'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">确认密码：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}' v-model="ruleForm.mima2" type="password" class="uni-input" name="" placeholder="确认密码" />
			</view>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='laoren'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">姓名：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.xingming"  type="text"  class="uni-input" name="" placeholder="请输入姓名" />
			</view>
            <view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='laoren'" class="">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">性别：</view>
				<picker :style='{"width":"100%","margin":"0","display":"flex","height":"auto"}' v-if="tableName=='laoren'"  @change="laorenxingbieChange" :value="laorenxingbieIndex" :range="laorenxingbieOptions">
					<view>
						<view :style='{"padding":"0 20rpx","lineHeight":"80rpx","fontSize":"28rpx","color":"#6B6153","flex":"1"}' class="uni-input">{{ruleForm.xingbie?ruleForm.xingbie:"请选择性别"}}</view>
					</view>
				</picker>
			</view>
			<!-- <view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='laoren'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">老人电话：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.laorendianhua"  type="text"  class="uni-input" name="" placeholder="老人电话" />
			</view> -->

			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='laoren'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">电话：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.zhanghao"  @input="syncLaorenPhone" type="text"  class="uni-input" name="" placeholder="请输入手机号" />
			</view>

			
            <view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='laoren'" @tap="laorentouxiangTap" class="">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">头像：</view>
				<image :style='{"width":"120rpx","borderRadius":"16rpx","display":"block","height":"120rpx"}' v-if="ruleForm.touxiang" class="avator" :src="baseUrl+ruleForm.touxiang" mode=""></image>
                <image :style='{"width":"120rpx","borderRadius":"16rpx","display":"block","height":"120rpx"}' v-else class="avator" src="../../static/gen/upload.png" mode=""></image>
            </view>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='yuangong'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">账号：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.yuangongzhanghao"  type="text"  class="uni-input" name="" placeholder="请输入手机号" />
			</view>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='yuangong'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">密码：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.mima" type="password"  class="uni-input" name="" placeholder="请输入密码" />
			</view>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='yuangong'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">确认密码：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}' v-model="ruleForm.mima2" type="password" class="uni-input" name="" placeholder="请确认密码" />
			</view>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='yuangong'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">姓名：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.yuangongxingming"  type="text"  class="uni-input" name="" placeholder="请输入姓名" />
			</view>
            <view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='yuangong'" class="">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">性别：</view>
				<picker :style='{"width":"100%","margin":"0","display":"flex","height":"auto"}' v-if="tableName=='yuangong'"  @change="yuangongxingbieChange" :value="yuangongxingbieIndex" :range="yuangongxingbieOptions">
					<view>
						<view :style='{"padding":"0 20rpx","lineHeight":"80rpx","fontSize":"28rpx","color":"#6B6153","flex":"1"}' class="uni-input">{{ruleForm.xingbie?ruleForm.xingbie:"请选择性别"}}</view>
					</view>
				</picker>
			</view>
			<view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='yuangong'" class="uni-form-item uni-column">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">电话：</view>
				<input :style='{"border":"none","padding":"0px 24rpx","margin":"0px","borderColor":"#D6D6D6","color":"rgb(0, 0, 0)","borderRadius":"0","flex":"1","background":"none","borderWidth":"0 0 2rpx 0 ","fontSize":"28rpx","borderStyle":"solid","height":"80rpx"}'  v-model="ruleForm.yuangongzhanghao"  type="text"  class="uni-input" name="" placeholder="请输入电话" />
			</view>
            <view :style='{"border":"none","width":"100%","margin":"0 0 40rpx 0","alignItems":"center","display":"flex","height":"auto"}' v-if="tableName=='yuangong'" @tap="yuangongtouxiangTap" class="">
				<view :style='{"padding":"0","whiteSpace":"nowrap","color":"#707070","borderRadius":"0","textAlign":"center","background":"none","flex":"none","width":"auto","lineHeight":"50rpx","fontSize":"28rpx","height":"50rpx"}' class="label">头像：</view>
				<image :style='{"width":"120rpx","borderRadius":"16rpx","display":"block","height":"120rpx"}' v-if="ruleForm.touxiang" class="avator" :src="baseUrl+ruleForm.touxiang" mode=""></image>
                <image :style='{"width":"120rpx","borderRadius":"16rpx","display":"block","height":"120rpx"}' v-else class="avator" src="../../static/gen/upload.png" mode=""></image>
            </view>
			<button :style='{"border":"0","padding":"0px","margin":"0 0 24rpx 0","color":"#fff","borderRadius":"8rpx","background":"linear-gradient( 135deg, #9EF0EA 0%, #99ABFF 100%)","width":"100%","lineHeight":"80rpx","fontSize":"32rpx","fontWeight":"600","height":"80rpx"}' class="btn-submit" @tap="register" type="primary">注册</button>
			
			<view class="idea1" :style='{"width":"100%","background":"red","display":"none","height":"80rpx"}'>idea1</view>
			<view class="idea2" :style='{"width":"100%","background":"red","display":"none","height":"80rpx"}'>idea2</view>
			<view class="idea3" :style='{"width":"100%","background":"red","display":"none","height":"80rpx"}'>idea3</view>
		</view>
	</view>
</view>
</template>

<script>
    import multipleSelect from "@/components/momo-multipleSelect/momo-multipleSelect";
	export default {
		data() {
			return {
                laorenxingbieOptions: [],
                laorenxingbieIndex: 0,
                yuangongxingbieOptions: [],
                yuangongxingbieIndex: 0,
				ruleForm: {
                zhanghao: '',
                mima: '',
                xingming: '',
                xingbie: '',
                laorendianhua: '',
                touxiang: '',
                jifen: '1',
                status: '',
                yuangongzhanghao: '',
                mima: '',
                yuangongxingming: '',
                xingbie: '',
                yuangongdianhua: '',
                touxiang: '',
                jifen: '1',
				},
				tableName:""
			}
		},
        components: {
            multipleSelect
        },
        computed: {
            baseUrl() {
                return this.$base.url;
            },
        },
		async onLoad() {
			let res = [];
			let table = uni.getStorageSync("loginTable");
            this.tableName = table;

                        // 自定义下拉框值
			if(this.tableName=='laoren'){
                this.laorenxingbieOptions = "男,女".split(',');
				this.ruleForm.xingbie=this.laorenxingbieOptions[0]
			}
            if(`laoren` == this.tableName){
                this.ruleForm.jifen='1'
            }
                        // 自定义下拉框值
			if(this.tableName=='yuangong'){
                this.yuangongxingbieOptions = "男,女".split(',');
				this.ruleForm.xingbie=this.yuangongxingbieOptions[0]
			}
            if(`yuangong` == this.tableName){
                this.ruleForm.jifen='1'
            }
			
			this.styleChange()
		},
		methods: {

            // 下拉变化
            laorenxingbieChange(e) {
                    this.laorenxingbieIndex = e.target.value
                    this.ruleForm.xingbie = this.laorenxingbieOptions[this.laorenxingbieIndex]
            },
            laorentouxiangTap() {
                let _this = this;
                this.$api.upload(function(res) {
                    _this.ruleForm.touxiang = 'upload/' + res.file;
					_this.$forceUpdate();
                });
            },
            // 下拉变化
            yuangongxingbieChange(e) {
                    this.yuangongxingbieIndex = e.target.value
                    this.ruleForm.xingbie = this.yuangongxingbieOptions[this.yuangongxingbieIndex]
            },
            yuangongtouxiangTap() {
                let _this = this;
                this.$api.upload(function(res) {
                    _this.ruleForm.touxiang = 'upload/' + res.file;
					_this.$forceUpdate();
                });
            },

            toggleTab(str) {
                this.$refs[str].show();
            },

			styleChange() {
				this.$nextTick(()=>{
					// document.querySelectorAll('.uni-input .uni-input-input').forEach(el=>{
					//   el.style.backgroundColor = this.registerFrom.content.input.backgroundColor
					// })
				})
			},
			// 获取uuid
			getUUID () {
				return new Date().getTime();
			},
			// 注册
			async register() {
				
				if((!this.ruleForm.zhanghao) && `laoren` == this.tableName){
					this.$utils.msg(`账号不能为空`);
					return
				}
				if((!this.ruleForm.mima) && `laoren` == this.tableName){
					this.$utils.msg(`密码不能为空`);
					return
				}
                if(`laoren` == this.tableName && (this.ruleForm.mima!=this.ruleForm.mima2)){
                    this.$utils.msg(`两次密码输入不一致`);
                    return
                }
				if((!this.ruleForm.xingming) && `laoren` == this.tableName){
					this.$utils.msg(`姓名不能为空`);
					return
				}
				if(`laoren` == this.tableName && this.ruleForm.laorendianhua&&(!this.$validate.isMobile(this.ruleForm.laorendianhua))){
					this.$utils.msg(`老人电话应输入手机格式`);
					return
				}
				if(`laoren` == this.tableName && this.ruleForm.zhanghao && this.ruleForm.zhanghao.length !== 11){
					this.$utils.msg(`手机号必须为11位`);
					return
				}
				if(`laoren` == this.tableName && this.ruleForm.jifen&&(!this.$validate.isNumber(this.ruleForm.jifen))){
					this.$utils.msg(`积分应输入数字`);
					return
				}
				if(`laoren` == this.tableName && this.ruleForm.status&&(!this.$validate.isIntNumer(this.ruleForm.status))){
					this.$utils.msg(`状态应输入整数`);
					return
				}
				if((!this.ruleForm.yuangongzhanghao) && `yuangong` == this.tableName){
					this.$utils.msg(`账号不能为空`);
					return
				}
				if((!this.ruleForm.mima) && `yuangong` == this.tableName){
					this.$utils.msg(`密码不能为空`);
					return
				}
                if(`yuangong` == this.tableName && (this.ruleForm.mima!=this.ruleForm.mima2)){
                    this.$utils.msg(`两次密码输入不一致`);
                    return
                }
				if((!this.ruleForm.yuangongxingming) && `yuangong` == this.tableName){
					this.$utils.msg(`姓名不能为空`);
					return
				}
				if(`yuangong` == this.tableName && this.ruleForm.yuangongdianhua&&(!this.$validate.isMobile(this.ruleForm.yuangongdianhua))){
					this.$utils.msg(`员工电话应输入手机格式`);
					return
				}
				if(`yuangong` == this.tableName && this.ruleForm.yuangongzhanghao && this.ruleForm.yuangongzhanghao.length !== 11){
					this.$utils.msg(`手机号必须为11位`);
					return
				}
				if(`yuangong` == this.tableName && this.ruleForm.jifen&&(!this.$validate.isNumber(this.ruleForm.jifen))){
					this.$utils.msg(`积分应输入数字`);
					return
				}

				// 在提交前确保laorendianhua字段与zhanghao同步
				if(`laoren` == this.tableName) {
					this.ruleForm.laorendianhua = this.ruleForm.zhanghao;
				}
				if(`yuangong` == this.tableName) {
					this.ruleForm.yuangongdianhua = this.ruleForm.yuangongzhanghao;
				}

				await this.$api.register(`${this.tableName}`, this.ruleForm);
				this.$utils.msgBack('注册成功');;
			},
			syncLaorenPhone(e) {
				// 同步电话号码到laorendianhua字段
				this.ruleForm.laorendianhua = this.ruleForm.zhanghao;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		min-height: calc(100vh - 44px);
		box-sizing: border-box;
	}
</style>
